{% extends "@CoreBundle/layout/main.html.twig" %}
{% import "@QaBundleAdmin/macros/chaptersub_tree.html.twig" as macros %}

{% block page_title %}章节点管理{% endblock %}
{% block breadcrumb %}
  <li class="breadcrumb-item"><a href="{{ path("qa_admin_chapter_index") }}">试题管理</a></li>
  <li class="breadcrumb-item">{{ chapter['name'] }}</li>
{% endblock %}

{% block body_custom_javascript %}
  <script>
    $(function(){

      $('#tree').nestable({scroll:true});
      $('.dd').nestable('collapseAll');
      
      $('.tree-tools').on('click', function(e){
        var action = $(this).data('action');
        if (action === 'expand') {
          $('.dd').nestable('expandAll');
        }
        if (action === 'collapse') {
          $('.dd').nestable('collapseAll');
        }
        $('.tree-tools').removeClass("active");
        $(this).addClass("active");
      });

      $("#sortSave").click(function(){
        var serialize = $('#tree').nestable('serialize');
        requestPost('{{ path('qa_admin_chaptersub_updateSort', {chapterId:chapterId}) }}', serialize);
      });
    });
  </script>
{% endblock %}

{% block page %}
    <div class="row">
      <div class="col-md-6">
        <div class="card">
          <div class="card-header">
            <div class="btn-group">
              <button class="btn btn-primary btn-sm tree-tools" data-action="expand" title="展开">
                <i class="mdi mdi-plus-box-outline"></i>&nbsp;展开
              </button>
              <button class="btn btn-primary btn-sm tree-tools active" data-action="collapse"
                      title="收起">
                <i class="mdi mdi-minus-box-outline"></i>&nbsp;收起
              </button>
            </div>
            {% if is_authorized('qa_admin_chaptersub_updateSort') %}
              <div class="btn-group">
                <button class="btn btn-info btn-sm" id="sortSave" title="保存">
                  <i class="mdi mdi-content-save"></i><span class="hidden-xs">&nbsp;保存排序 </span>
                </button>
              </div>
            {% endif %}
          </div>
          <!-- /.box-header -->
          <div class="card-body table-responsive">
            <div class="dd" id="tree">
              {{ macros.chaptersub_tree(list) }}
            </div>
          </div>
          <!-- /.box-body -->
        </div>
      </div>
      {% if is_authorized('qa_admin_chaptersub_adddo') %}
        <div class="col-md-6">
          {{ addFormData|raw }}
        </div>
      {% endif %}
    </div>
{% endblock %}
